package com.main.tripplanner.clientservices;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.main.tripplanner.algorithms.RoutePlanningOpt;
import com.main.tripplanner.dao.CountryDAO;
import com.main.tripplanner.persistent.Country;
import com.main.tripplanner.persistent.Dosage;
import com.main.tripplanner.persistent.Route;
import com.main.tripplanner.persistent.Ticket;

@Service
public class PlanRouteClientService {
	@Autowired
	private RoutePlanningOpt routePlanningOpt;
	@Autowired
	private CountryDAO countryDAO;
	
	private static PlanRouteClientService service = null;
	
	public static PlanRouteClientService getService() {
		if (service == null) {
			service = new PlanRouteClientService();
			return service;
		}
		return null;
	}
	
	public Ticket getResponse(Ticket ticket, String countryId, Dosage dosage, String travelTimeString) {
		Country country = countryDAO.getCountryById(countryId);
		Route route = routePlanningOpt.planRoute(country, dosage, Integer.parseInt(travelTimeString));
		ticket.setResponse(route.toJsonString(true));
		return ticket;
	}
}
